package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.FoodKnowledgeDao;
import com.itheima.dao.SportKnowledgeDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Food;
import com.itheima.pojo.Sport;
import com.itheima.service.FoodKnowledgeService;
import com.itheima.service.SportKnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author xw
 * @date 2020-08-22 20:40
 */
@Service(interfaceClass = SportKnowledgeService.class)
@Transactional

public class SportKnowledgeServiceImpl implements SportKnowledgeService{
     @Autowired
     private SportKnowledgeDao sportKnowledgeDao;

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //根据条件分页查询检查项信息
        Page<Sport> page = sportKnowledgeDao.selectByCondition(queryPageBean.getQueryString());
        //构建分页数据返回
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Sport sport) {
        sportKnowledgeDao.add(sport);
    }

    @Override
    public void deleteById(Integer id) {
       sportKnowledgeDao.deleteById(id);
    }

    @Override
    public Sport findById(int id) {
        return sportKnowledgeDao.findById(id);
    }

    @Override
    public void edit(Sport sport) {
      sportKnowledgeDao.update(sport);
    }

    @Override
    public void adds(List<Sport> sport) {
          if(sport!=null&&sport.size()>0){
              for (Sport sport1 : sport) {
                  sportKnowledgeDao.adds(sport1);
              }
          }
    }
}
